<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="button" id="othercheck" value="反选" /><br />
    <div id="div">

        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
        <input type="checkbox" /><br />
    </div>
    <script>
        /*   1.完成 反选功能 */

        // 获取反选按钮
        let othercheck = document.getElementById("othercheck");
        // console.log(othercheck);
        othercheck.onclick = function() {
            //获取div中所有多选框
            let inputs = document.getElementById("div").getElementsByTagName("input");
            // console.log(inputs);
            // 遍历多选框
            for (let i = 0; i < inputs.length; i++) {
                let input1 = inputs[i];
                // 判断多选框的选中状态
                if (input1.checked == true) {
                    input1.checked = false;
                } else {
                    input1.checked = true;
                }
            }
        };
    </script>
</body>

</html>